﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Models;


namespace DAL
{
    public class LoginService
    {
        /// <summary>
        /// 判断是否能登陆
        /// </summary>
        /// <param name="id"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public bool isLogin(string id,string pwd)
        {
            int num = 0;
            try
            {
                string sql = string.Format("select count(*) from accounts where login='{0}' and password='{1}' and access_level='100'", id, pwd);
                MySqlCommand com = new MySqlCommand(sql, DBHelper.con);
                DBHelper.con.Open();
                num = Convert.ToInt32(com.ExecuteScalar());
            }
            catch
            {
                Error.s = "读取数据库时发生错误！";
            }
            finally
            {
                DBHelper.con.Close();
                DBHelper.con.Dispose();
            }
            if (num == 0)
            {
                return false;
            }
            return true;


        }

        public bool isLogin(int type)
        {
            int num = 0;
            string sql = string.Empty;
            try
            {
                switch (type)
                {
                    case 1:
                        sql = "select count(*)  from inn where npcid = 70096 and room_number=13";
                        break;
                    case 2:
                        sql = "select count(*)  from magic_doll where item_id = 47110 and doll_id=92110";
                        break;
                }
                
                MySqlCommand com = new MySqlCommand(sql, DBHelper.con);
                DBHelper.con.Open();
                num = Convert.ToInt32(com.ExecuteScalar());
            }
            catch
            {
                Error.s = "读取数据库时发生错误！";
            }
            finally
            {
                DBHelper.con.Close();
                DBHelper.con.Dispose();
            }
            if (num == 0)
            {
                return false;
            }
            return true;
        }
    }
}
